/**
 *
 */
import Util;
import OSS;
import OpenPlatform;
import OSSUtil;
import FileForm;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = 'regional';
  
  checkConfig(config);
  @endpoint = getEndpoint('imageseg', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ChangeSkyRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/ChangeSky/ChangeSky2.jpg'),
  replaceImageURL?: string(name='ReplaceImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/ChangeSky/ChangeSky6.jpg'),
}

model ChangeSkyAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/ChangeSky/ChangeSky2.jpg'),
  replaceImageURLObject?: readable(name='ReplaceImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/ChangeSky/ChangeSky6.jpg'),
}

model ChangeSkyResponseBody = {
  data?: {
    imageURL?: string(name='ImageURL', example='http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_skySegmentator/2020-7-24/invi_skySegmentator_015955791588111000000_5pn2QM.jpg?Expires=1595580958&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=Sq4po8h3WAj%2BBFrCgTP3ghlXn4****'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='F9D60817-EC5A-4BAC-9092-4AD42220CFA8'),
}

model ChangeSkyResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ChangeSkyResponseBody(name='body'),
}

/**
 * @param request ChangeSkyRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ChangeSkyResponse
 */
async function changeSkyWithOptions(request: ChangeSkyRequest, runtime: Util.RuntimeOptions): ChangeSkyResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  if (!Util.isUnset(request.replaceImageURL)) {
    query['ReplaceImageURL'] = request.replaceImageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ChangeSky',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request ChangeSkyRequest
 * @return ChangeSkyResponse
 */
async function changeSky(request: ChangeSkyRequest): ChangeSkyResponse {
  var runtime = new Util.RuntimeOptions{};
  return changeSkyWithOptions(request, runtime);
}

async function changeSkyAdvance(request: ChangeSkyAdvanceRequest, runtime: Util.RuntimeOptions): ChangeSkyResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var changeSkyReq = new ChangeSkyRequest{};
  OpenApiUtil.convert(request, changeSkyReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    changeSkyReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  if(!Util.isUnset(request.replaceImageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.replaceImageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    changeSkyReq.replaceImageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var changeSkyResp = changeSkyWithOptions(changeSkyReq, runtime);
  return changeSkyResp;
}

model GetAsyncJobResultRequest {
  jobId?: string(name='JobId', description='This parameter is required.', example='E75FE679-0303-4DD1-8252-1143B4FA8A27'),
}

model GetAsyncJobResultResponseBody = {
  data?: {
    errorCode?: string(name='ErrorCode', example='InvalidParameter'),
    errorMessage?: string(name='ErrorMessage', example='paramsIllegal'),
    jobId?: string(name='JobId', example='49E2CC28-ED1D-4CC5-854D-7D0AE2B20976'),
    result?: string(name='Result', example='{"ImageUrl":"http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_/2020-4-2/invi__015858226731531000018_UE7B9p.png?Expires=1585824473&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSR****&Signature=etyeYQQ%2BWAyQTqQKd8Xq0GiOW****"}'),
    status?: string(name='Status', example='PROCESS_SUCCESS'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='43A0AEB6-45F4-4138-8E89-E1A5D63200E3'),
}

model GetAsyncJobResultResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: GetAsyncJobResultResponseBody(name='body'),
}

/**
 * @param request GetAsyncJobResultRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return GetAsyncJobResultResponse
 */
async function getAsyncJobResultWithOptions(request: GetAsyncJobResultRequest, runtime: Util.RuntimeOptions): GetAsyncJobResultResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.jobId)) {
    body['JobId'] = request.jobId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'GetAsyncJobResult',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request GetAsyncJobResultRequest
 * @return GetAsyncJobResultResponse
 */
async function getAsyncJobResult(request: GetAsyncJobResultRequest): GetAsyncJobResultResponse {
  var runtime = new Util.RuntimeOptions{};
  return getAsyncJobResultWithOptions(request, runtime);
}

model ParseFaceRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/ParseFace/ParseFace1.jpg'),
}

model ParseFaceAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/ParseFace/ParseFace1.jpg'),
}

model ParseFaceResponseBody = {
  data?: {
    elements?: [ 
      {
        imageURL?: string(name='ImageURL', example='http://vibktprfx-prod-prod-aic-gd-cn-shanghai.oss-cn-shanghai.aliyuncs.com/fivesensesegmenter/prod/560FA2E7-FDC6-59A5-ABDD-D62A05146734/skin/_18dd_20211231-040658.png?Expires=1640925418&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=2g0M88wZl%2Bn4t4gzQX%2BTIskpWB****'),
        name?: string(name='Name', example='skin'),
      }
    ](name='Elements'),
    originImageURL?: string(name='OriginImageURL', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/ParseFace/ParseFace1.jpg'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='D6C24839-91A7-41DA-B31F-98F08EF80CC0'),
}

model ParseFaceResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ParseFaceResponseBody(name='body'),
}

/**
 * @param request ParseFaceRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ParseFaceResponse
 */
async function parseFaceWithOptions(request: ParseFaceRequest, runtime: Util.RuntimeOptions): ParseFaceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ParseFace',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request ParseFaceRequest
 * @return ParseFaceResponse
 */
async function parseFace(request: ParseFaceRequest): ParseFaceResponse {
  var runtime = new Util.RuntimeOptions{};
  return parseFaceWithOptions(request, runtime);
}

async function parseFaceAdvance(request: ParseFaceAdvanceRequest, runtime: Util.RuntimeOptions): ParseFaceResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var parseFaceReq = new ParseFaceRequest{};
  OpenApiUtil.convert(request, parseFaceReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    parseFaceReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var parseFaceResp = parseFaceWithOptions(parseFaceReq, runtime);
  return parseFaceResp;
}

model RefineMaskRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/RefineMask/RefineMask1.jpg'),
  maskImageURL?: string(name='MaskImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/RefineMask/RefineMask6.jpg'),
}

model RefineMaskAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/RefineMask/RefineMask1.jpg'),
  maskImageURLObject?: readable(name='MaskImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/RefineMask/RefineMask6.jpg'),
}

model RefineMaskResponseBody = {
  data?: {
    elements?: [ 
      {
        imageURL?: string(name='ImageURL', example='http://algo-app-taobao-mm-cn-shanghai-prod.oss-cn-shanghai.aliyuncs.com/pixelai-portrait-beauty%2F2020_03_04%2F61f544a1a5004c88a2bf29452db494e9.jpeg?OSSAccessKeyId=LTAI4Fmdm1gQonFLrghJ****&Expires=1583406122&Signature=Heet1ivG0xFP3YlO6usvd0pmrH****'),
      }
    ](name='Elements'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='E948F80B-86D9-54E0-9FF9-ACF3B1DA83C4'),
}

model RefineMaskResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: RefineMaskResponseBody(name='body'),
}

/**
 * @param request RefineMaskRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return RefineMaskResponse
 */
async function refineMaskWithOptions(request: RefineMaskRequest, runtime: Util.RuntimeOptions): RefineMaskResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  if (!Util.isUnset(request.maskImageURL)) {
    body['MaskImageURL'] = request.maskImageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'RefineMask',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request RefineMaskRequest
 * @return RefineMaskResponse
 */
async function refineMask(request: RefineMaskRequest): RefineMaskResponse {
  var runtime = new Util.RuntimeOptions{};
  return refineMaskWithOptions(request, runtime);
}

async function refineMaskAdvance(request: RefineMaskAdvanceRequest, runtime: Util.RuntimeOptions): RefineMaskResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var refineMaskReq = new RefineMaskRequest{};
  OpenApiUtil.convert(request, refineMaskReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    refineMaskReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  if(!Util.isUnset(request.maskImageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.maskImageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    refineMaskReq.maskImageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var refineMaskResp = refineMaskWithOptions(refineMaskReq, runtime);
  return refineMaskResp;
}

model SegmentBodyRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentBody/SegmentBody1.png'),
  returnForm?: string(name='ReturnForm', example='mask'),
}

model SegmentBodyAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentBody/SegmentBody1.png'),
  returnForm?: string(name='ReturnForm', example='mask'),
}

model SegmentBodyResponseBody = {
  data?: {
    imageURL?: string(name='ImageURL', example='http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_humansegmenter/2021-3-31/invi_humansegmenter_016171823500001081370_Ej0WwO.jpg?Expires=1617184150&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=ZwaWXpAOMzHar%2B1wVO7zeSD83r****'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='30EDCEEA-2806-44C6-AF0B-0988849106FE'),
}

model SegmentBodyResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentBodyResponseBody(name='body'),
}

/**
 * @param request SegmentBodyRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentBodyResponse
 */
async function segmentBodyWithOptions(request: SegmentBodyRequest, runtime: Util.RuntimeOptions): SegmentBodyResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  if (!Util.isUnset(request.returnForm)) {
    query['ReturnForm'] = request.returnForm;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SegmentBody',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentBodyRequest
 * @return SegmentBodyResponse
 */
async function segmentBody(request: SegmentBodyRequest): SegmentBodyResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentBodyWithOptions(request, runtime);
}

async function segmentBodyAdvance(request: SegmentBodyAdvanceRequest, runtime: Util.RuntimeOptions): SegmentBodyResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentBodyReq = new SegmentBodyRequest{};
  OpenApiUtil.convert(request, segmentBodyReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentBodyReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentBodyResp = segmentBodyWithOptions(segmentBodyReq, runtime);
  return segmentBodyResp;
}

model SegmentClothRequest {
  clothClass?: [ string ](name='ClothClass'),
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentCloth/SegmentCloth1.jpg'),
  outMode?: long(name='OutMode'),
  returnForm?: string(name='ReturnForm'),
}

model SegmentClothAdvanceRequest {
  clothClass?: [ string ](name='ClothClass'),
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentCloth/SegmentCloth1.jpg'),
  outMode?: long(name='OutMode'),
  returnForm?: string(name='ReturnForm'),
}

model SegmentClothResponseBody = {
  data?: {
    elements?: [ 
      {
        classUrl?: map[string]string(name='ClassUrl'),
        imageURL?: string(name='ImageURL', example='http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/clothingsegmentation-2020-06-17-16-54-40-688c84cbbd-hnqfq/2020-6-18/invi__015924459307821000041_IIVHoM.png?Expires=1592447730&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=Hy8pn3IQj8nuKN0LEaC57cee9L****'),
      }
    ](name='Elements'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='BCE049A3-FE69-41CF-A870-5970156388A7'),
}

model SegmentClothResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentClothResponseBody(name='body'),
}

/**
 * @param request SegmentClothRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentClothResponse
 */
async function segmentClothWithOptions(request: SegmentClothRequest, runtime: Util.RuntimeOptions): SegmentClothResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.clothClass)) {
    query['ClothClass'] = request.clothClass;
  }
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  if (!Util.isUnset(request.outMode)) {
    query['OutMode'] = request.outMode;
  }
  if (!Util.isUnset(request.returnForm)) {
    query['ReturnForm'] = request.returnForm;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SegmentCloth',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentClothRequest
 * @return SegmentClothResponse
 */
async function segmentCloth(request: SegmentClothRequest): SegmentClothResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentClothWithOptions(request, runtime);
}

async function segmentClothAdvance(request: SegmentClothAdvanceRequest, runtime: Util.RuntimeOptions): SegmentClothResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentClothReq = new SegmentClothRequest{};
  OpenApiUtil.convert(request, segmentClothReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentClothReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentClothResp = segmentClothWithOptions(segmentClothReq, runtime);
  return segmentClothResp;
}

model SegmentCommodityRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentCommodity/SegmentCommodity1.jpg'),
  returnForm?: string(name='ReturnForm', example='mask'),
}

model SegmentCommodityAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentCommodity/SegmentCommodity1.jpg'),
  returnForm?: string(name='ReturnForm', example='mask'),
}

model SegmentCommodityResponseBody = {
  data?: {
    imageURL?: string(name='ImageURL', example='http://luban-vgd-invi.oss-cn-hangzhou.aliyuncs.com/upload/result_segmenter/2019-12-20/invi_segmenter_015768355410261076021_Z3t0fc.png?Expires=1577094741&OSSAccessKeyId=LTAI4Fc5SVvzUQ19K1Cz****&Signature=pkaKK3VlfsTR2r%2BYycJzTVEEos****'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='D6C24839-91A7-41DA-B31F-98F08EF80CC0'),
}

model SegmentCommodityResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentCommodityResponseBody(name='body'),
}

/**
 * @param request SegmentCommodityRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentCommodityResponse
 */
async function segmentCommodityWithOptions(request: SegmentCommodityRequest, runtime: Util.RuntimeOptions): SegmentCommodityResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  if (!Util.isUnset(request.returnForm)) {
    query['ReturnForm'] = request.returnForm;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SegmentCommodity',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentCommodityRequest
 * @return SegmentCommodityResponse
 */
async function segmentCommodity(request: SegmentCommodityRequest): SegmentCommodityResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentCommodityWithOptions(request, runtime);
}

async function segmentCommodityAdvance(request: SegmentCommodityAdvanceRequest, runtime: Util.RuntimeOptions): SegmentCommodityResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentCommodityReq = new SegmentCommodityRequest{};
  OpenApiUtil.convert(request, segmentCommodityReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentCommodityReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentCommodityResp = segmentCommodityWithOptions(segmentCommodityReq, runtime);
  return segmentCommodityResp;
}

model SegmentCommonImageRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentCommonImage/SegmentCommonImage1.jpg'),
  returnForm?: string(name='ReturnForm', example='mask'),
}

model SegmentCommonImageAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentCommonImage/SegmentCommonImage1.jpg'),
  returnForm?: string(name='ReturnForm', example='mask'),
}

model SegmentCommonImageResponseBody = {
  data?: {
    imageURL?: string(name='ImageURL', example='http://luban-vgd-invi.oss-cn-hangzhou.aliyuncs.com/upload/result_segmenter/2019-12-20/invi_segmenter_015768355410261076021_Z3t0fc.png?Expires=1577094741&OSSAccessKeyId=LTAI4Fc5SVvzUQ19K1Cz****&Signature=pkaKK3VlfsTR2r%2BYycJzTVEEos****'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='1B8BEF02-0672-44CA-A974-4D6FAC392497'),
}

model SegmentCommonImageResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentCommonImageResponseBody(name='body'),
}

/**
 * @param request SegmentCommonImageRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentCommonImageResponse
 */
async function segmentCommonImageWithOptions(request: SegmentCommonImageRequest, runtime: Util.RuntimeOptions): SegmentCommonImageResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  if (!Util.isUnset(request.returnForm)) {
    query['ReturnForm'] = request.returnForm;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SegmentCommonImage',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentCommonImageRequest
 * @return SegmentCommonImageResponse
 */
async function segmentCommonImage(request: SegmentCommonImageRequest): SegmentCommonImageResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentCommonImageWithOptions(request, runtime);
}

async function segmentCommonImageAdvance(request: SegmentCommonImageAdvanceRequest, runtime: Util.RuntimeOptions): SegmentCommonImageResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentCommonImageReq = new SegmentCommonImageRequest{};
  OpenApiUtil.convert(request, segmentCommonImageReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentCommonImageReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentCommonImageResp = segmentCommonImageWithOptions(segmentCommonImageReq, runtime);
  return segmentCommonImageResp;
}

model SegmentFoodRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentFood/SegmentFood5.jpg'),
  returnForm?: string(name='ReturnForm', example='mask'),
}

model SegmentFoodAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentFood/SegmentFood5.jpg'),
  returnForm?: string(name='ReturnForm', example='mask'),
}

model SegmentFoodResponseBody = {
  data?: {
    imageURL?: string(name='ImageURL', example='http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/foodsegmenter-2020-06-17-15-24-00-8658fc85b8-8ds8k/2020-6-18/invi__015924442076191000002_WqJ99N.png?Expires=1592446007&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=5ITSd6ndSuP7pUfoDFpgLPUOGg****'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='38265D08-AD0F-4752-8E96-D1D9FB96C3D9'),
}

model SegmentFoodResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentFoodResponseBody(name='body'),
}

/**
 * @param request SegmentFoodRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentFoodResponse
 */
async function segmentFoodWithOptions(request: SegmentFoodRequest, runtime: Util.RuntimeOptions): SegmentFoodResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  if (!Util.isUnset(request.returnForm)) {
    query['ReturnForm'] = request.returnForm;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SegmentFood',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentFoodRequest
 * @return SegmentFoodResponse
 */
async function segmentFood(request: SegmentFoodRequest): SegmentFoodResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentFoodWithOptions(request, runtime);
}

async function segmentFoodAdvance(request: SegmentFoodAdvanceRequest, runtime: Util.RuntimeOptions): SegmentFoodResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentFoodReq = new SegmentFoodRequest{};
  OpenApiUtil.convert(request, segmentFoodReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentFoodReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentFoodResp = segmentFoodWithOptions(segmentFoodReq, runtime);
  return segmentFoodResp;
}

model SegmentHDBodyRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentHDBody/SegmentHDBody1.jpg'),
}

model SegmentHDBodyAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentHDBody/SegmentHDBody1.jpg'),
}

model SegmentHDBodyResponseBody = {
  data?: {
    imageURL?: string(name='ImageURL', example='http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/segmenthdbody-2020-05-18-16-27-45-675d9884d7-kd9dz/2020-5-18/invi_humansegmenter_015897914589851000001_wQbLq9.png?Expires=1589793259&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=Lx6xSS0t7lqEvy5Qd1keccIAjL****'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='A8D3F5C3-E414-4981-8D84-E2CADF0B7CBC'),
}

model SegmentHDBodyResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentHDBodyResponseBody(name='body'),
}

/**
 * @param request SegmentHDBodyRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentHDBodyResponse
 */
async function segmentHDBodyWithOptions(request: SegmentHDBodyRequest, runtime: Util.RuntimeOptions): SegmentHDBodyResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SegmentHDBody',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentHDBodyRequest
 * @return SegmentHDBodyResponse
 */
async function segmentHDBody(request: SegmentHDBodyRequest): SegmentHDBodyResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentHDBodyWithOptions(request, runtime);
}

async function segmentHDBodyAdvance(request: SegmentHDBodyAdvanceRequest, runtime: Util.RuntimeOptions): SegmentHDBodyResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentHDBodyReq = new SegmentHDBodyRequest{};
  OpenApiUtil.convert(request, segmentHDBodyReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentHDBodyReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentHDBodyResp = segmentHDBodyWithOptions(segmentHDBodyReq, runtime);
  return segmentHDBodyResp;
}

model SegmentHDCommonImageRequest {
  imageUrl?: string(name='ImageUrl', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentHDCommonImage/SegmentHDCommonImage1.jpg'),
}

model SegmentHDCommonImageAdvanceRequest {
  imageUrlObject?: readable(name='ImageUrl', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentHDCommonImage/SegmentHDCommonImage1.jpg'),
}

model SegmentHDCommonImageResponseBody = {
  data?: {
    imageUrl?: string(name='ImageUrl', example='http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_commoditysegmenter/2020-10-27/invi_commoditysegmenter_016037842193171000000_5pn2QM.png?Expires=1603786019&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=HwUztguGBYXmXGEmuTh%2FL3ztoh****'),
  }(name='Data'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId', example='EC994171-7964-44B3-85AF-A715CB56747D'),
}

model SegmentHDCommonImageResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentHDCommonImageResponseBody(name='body'),
}

/**
 * @param request SegmentHDCommonImageRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentHDCommonImageResponse
 */
async function segmentHDCommonImageWithOptions(request: SegmentHDCommonImageRequest, runtime: Util.RuntimeOptions): SegmentHDCommonImageResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageUrl)) {
    body['ImageUrl'] = request.imageUrl;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'SegmentHDCommonImage',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentHDCommonImageRequest
 * @return SegmentHDCommonImageResponse
 */
async function segmentHDCommonImage(request: SegmentHDCommonImageRequest): SegmentHDCommonImageResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentHDCommonImageWithOptions(request, runtime);
}

async function segmentHDCommonImageAdvance(request: SegmentHDCommonImageAdvanceRequest, runtime: Util.RuntimeOptions): SegmentHDCommonImageResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentHDCommonImageReq = new SegmentHDCommonImageRequest{};
  OpenApiUtil.convert(request, segmentHDCommonImageReq);

  if(!Util.isUnset(request.imageUrlObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageUrlObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentHDCommonImageReq.imageUrl = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentHDCommonImageResp = segmentHDCommonImageWithOptions(segmentHDCommonImageReq, runtime);
  return segmentHDCommonImageResp;
}

model SegmentHDSkyRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentHDSky/SegmentHDSky4.jpg'),
}

model SegmentHDSkyAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentHDSky/SegmentHDSky4.jpg'),
}

model SegmentHDSkyResponseBody = {
  data?: {
    imageURL?: string(name='ImageURL', example='http://vibktprfx-prod-prod-aic-gd-cn-shanghai.oss-cn-shanghai.aliyuncs.com/sky-segmentation-hd/res/1173F38F-B4F4-4A07-AB2E-D490C01347E5_0d56_20201027-061858.jpg?Expires=1603781339&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=2F8%2Bj%2FWruWOMqDezwpnJOkcNJD****'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='1173F38F-B4F4-4A07-AB2E-D490C01347E5'),
}

model SegmentHDSkyResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentHDSkyResponseBody(name='body'),
}

/**
 * @param request SegmentHDSkyRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentHDSkyResponse
 */
async function segmentHDSkyWithOptions(request: SegmentHDSkyRequest, runtime: Util.RuntimeOptions): SegmentHDSkyResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.imageURL)) {
    body['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'SegmentHDSky',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentHDSkyRequest
 * @return SegmentHDSkyResponse
 */
async function segmentHDSky(request: SegmentHDSkyRequest): SegmentHDSkyResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentHDSkyWithOptions(request, runtime);
}

async function segmentHDSkyAdvance(request: SegmentHDSkyAdvanceRequest, runtime: Util.RuntimeOptions): SegmentHDSkyResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentHDSkyReq = new SegmentHDSkyRequest{};
  OpenApiUtil.convert(request, segmentHDSkyReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentHDSkyReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentHDSkyResp = segmentHDSkyWithOptions(segmentHDSkyReq, runtime);
  return segmentHDSkyResp;
}

model SegmentHairRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentHair/SegmentHair1.jpg'),
}

model SegmentHairAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentHair/SegmentHair1.jpg'),
}

model SegmentHairResponseBody = {
  data?: {
    elements?: [ 
      {
        height?: int32(name='Height', example='180'),
        imageURL?: string(name='ImageURL', example='http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_HeadSegmenter/2021-12-31/invi_HeadSegmenter_016409228383064285967296_iPLUXA.png?Expires=1640924638&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=wpKOqSar1bYvGmlTMryfEH2Q9I****'),
        width?: int32(name='Width', example='113'),
        x?: int32(name='X', example='446'),
        y?: int32(name='Y', example='102'),
      }
    ](name='Elements'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='D6C24839-91A7-41DA-B31F-98F08EF80CC0'),
}

model SegmentHairResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentHairResponseBody(name='body'),
}

/**
 * @param request SegmentHairRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentHairResponse
 */
async function segmentHairWithOptions(request: SegmentHairRequest, runtime: Util.RuntimeOptions): SegmentHairResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SegmentHair',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentHairRequest
 * @return SegmentHairResponse
 */
async function segmentHair(request: SegmentHairRequest): SegmentHairResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentHairWithOptions(request, runtime);
}

async function segmentHairAdvance(request: SegmentHairAdvanceRequest, runtime: Util.RuntimeOptions): SegmentHairResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentHairReq = new SegmentHairRequest{};
  OpenApiUtil.convert(request, segmentHairReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentHairReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentHairResp = segmentHairWithOptions(segmentHairReq, runtime);
  return segmentHairResp;
}

model SegmentHeadRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentHead/SegmentHead1.jpg'),
  returnForm?: string(name='ReturnForm', example='mask'),
}

model SegmentHeadAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentHead/SegmentHead1.jpg'),
  returnForm?: string(name='ReturnForm', example='mask'),
}

model SegmentHeadResponseBody = {
  data?: {
    elements?: [ 
      {
        height?: int32(name='Height', example='180'),
        imageURL?: string(name='ImageURL', example='http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_headsegmenter/2020-6-2/invi_headsegmenter_015910809094981099086_TAamhR.png?Expires=1591082709&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=xuUE%2FbYeB9LpR18VXawOVeutQU****'),
        width?: int32(name='Width', example='116'),
        x?: int32(name='X', example='445'),
        y?: int32(name='Y', example='102'),
      }
    ](name='Elements'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='89BBDA42-E1CA-426E-9A46-C703D8DBB1E2'),
}

model SegmentHeadResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentHeadResponseBody(name='body'),
}

/**
 * @param request SegmentHeadRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentHeadResponse
 */
async function segmentHeadWithOptions(request: SegmentHeadRequest, runtime: Util.RuntimeOptions): SegmentHeadResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  if (!Util.isUnset(request.returnForm)) {
    query['ReturnForm'] = request.returnForm;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SegmentHead',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentHeadRequest
 * @return SegmentHeadResponse
 */
async function segmentHead(request: SegmentHeadRequest): SegmentHeadResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentHeadWithOptions(request, runtime);
}

async function segmentHeadAdvance(request: SegmentHeadAdvanceRequest, runtime: Util.RuntimeOptions): SegmentHeadResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentHeadReq = new SegmentHeadRequest{};
  OpenApiUtil.convert(request, segmentHeadReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentHeadReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentHeadResp = segmentHeadWithOptions(segmentHeadReq, runtime);
  return segmentHeadResp;
}

model SegmentSceneRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentScene/SegmentScene1.jpg'),
}

model SegmentSceneAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentScene/SegmentScene1.jpg'),
}

model SegmentSceneResponseBody = {
  data?: {
    imageURL?: string(name='ImageURL', example='http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_skySegmentator/2020-7-24/invi_skySegmentator_015955807385661000002_WqJ99N.jpg?Expires=1595582538&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=sBP5bQCErDolM4QQG5%2B0HozNoO****'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='78EC13BB-74C5-4FBE-916E-C98BD721ED61'),
}

model SegmentSceneResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentSceneResponseBody(name='body'),
}

/**
 * @param request SegmentSceneRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentSceneResponse
 */
async function segmentSceneWithOptions(request: SegmentSceneRequest, runtime: Util.RuntimeOptions): SegmentSceneResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SegmentScene',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentSceneRequest
 * @return SegmentSceneResponse
 */
async function segmentScene(request: SegmentSceneRequest): SegmentSceneResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentSceneWithOptions(request, runtime);
}

async function segmentSceneAdvance(request: SegmentSceneAdvanceRequest, runtime: Util.RuntimeOptions): SegmentSceneResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentSceneReq = new SegmentSceneRequest{};
  OpenApiUtil.convert(request, segmentSceneReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentSceneReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentSceneResp = segmentSceneWithOptions(segmentSceneReq, runtime);
  return segmentSceneResp;
}

model SegmentSkinRequest {
  URL?: string(name='URL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentSkin/SegmentSkin2.jpg'),
}

model SegmentSkinAdvanceRequest {
  URLObject?: readable(name='URL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentSkin/SegmentSkin2.jpg'),
}

model SegmentSkinResponseBody = {
  data?: {
    URL?: string(name='URL', example='http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/result_skinsegmenter/2020-9-27/invi_skinsegmenter_016011971641871000001_wQbLq9.jpg?Expires=1601198964&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=xjKc%2BScprmB86cxtI%2B1T0R6TlE****'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='DA007354-6CF5-45BE-8333-E06318D848C0'),
}

model SegmentSkinResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentSkinResponseBody(name='body'),
}

/**
 * @param request SegmentSkinRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentSkinResponse
 */
async function segmentSkinWithOptions(request: SegmentSkinRequest, runtime: Util.RuntimeOptions): SegmentSkinResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.URL)) {
    body['URL'] = request.URL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'SegmentSkin',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentSkinRequest
 * @return SegmentSkinResponse
 */
async function segmentSkin(request: SegmentSkinRequest): SegmentSkinResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentSkinWithOptions(request, runtime);
}

async function segmentSkinAdvance(request: SegmentSkinAdvanceRequest, runtime: Util.RuntimeOptions): SegmentSkinResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentSkinReq = new SegmentSkinRequest{};
  OpenApiUtil.convert(request, segmentSkinReq);

  if(!Util.isUnset(request.URLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.URLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentSkinReq.URL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentSkinResp = segmentSkinWithOptions(segmentSkinReq, runtime);
  return segmentSkinResp;
}

model SegmentSkyRequest {
  imageURL?: string(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentSky/SegmentSky5.jpg'),
}

model SegmentSkyAdvanceRequest {
  imageURLObject?: readable(name='ImageURL', description='This parameter is required.', example='http://viapi-test.oss-cn-shanghai.aliyuncs.com/viapi-3.0domepic/imageseg/SegmentSky/SegmentSky5.jpg'),
}

model SegmentSkyResponseBody = {
  data?: {
    imageURL?: string(name='ImageURL', example='http://viapi-cn-shanghai-dha-segmenter.oss-cn-shanghai.aliyuncs.com/upload/skysegmentation-2020-05-18-10-44-16-5bc8dc79f9-92b7z/2020-5-18/invi_skySegmentator_015897703560961000003_SqZLDv.png?Expires=1589772156&OSSAccessKeyId=LTAI4FoLmvQ9urWXgSRp****&Signature=gXrzAUl%2BvIdYbQ9XKdho54MlkX****'),
  }(name='Data'),
  requestId?: string(name='RequestId', example='80E9D0A0-0330-4210-9986-CAC50C922FF0'),
}

model SegmentSkyResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: SegmentSkyResponseBody(name='body'),
}

/**
 * @param request SegmentSkyRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return SegmentSkyResponse
 */
async function segmentSkyWithOptions(request: SegmentSkyRequest, runtime: Util.RuntimeOptions): SegmentSkyResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.imageURL)) {
    query['ImageURL'] = request.imageURL;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'SegmentSky',
    version = '2019-12-30',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @param request SegmentSkyRequest
 * @return SegmentSkyResponse
 */
async function segmentSky(request: SegmentSkyRequest): SegmentSkyResponse {
  var runtime = new Util.RuntimeOptions{};
  return segmentSkyWithOptions(request, runtime);
}

async function segmentSkyAdvance(request: SegmentSkyAdvanceRequest, runtime: Util.RuntimeOptions): SegmentSkyResponse {
  // Step 0: init client
  var accessKeyId = @credential.getAccessKeyId();
  var accessKeySecret = @credential.getAccessKeySecret();
  var securityToken = @credential.getSecurityToken();
  var credentialType = @credential.getType();
  var openPlatformEndpoint = @openPlatformEndpoint;
  if(Util.empty(openPlatformEndpoint)) {
    openPlatformEndpoint ='openplatform.aliyuncs.com';
  }
  if(Util.isUnset(credentialType)) {
    credentialType ='access_key';
  }
  var authConfig = new OpenApi.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    securityToken = securityToken,
    type = credentialType,
    endpoint = openPlatformEndpoint,
    protocol = @protocol,
    regionId = @regionId,
  };
  var authClient = new OpenPlatform(authConfig);
  var authRequest = new OpenPlatform.AuthorizeFileUploadRequest{
    product = 'imageseg',
    regionId = @regionId,
  };
  var authResponse = new OpenPlatform.AuthorizeFileUploadResponse{};
  var ossConfig = new OSS.Config{
    accessKeyId = accessKeyId,
    accessKeySecret = accessKeySecret,
    type = 'access_key',
    protocol = @protocol,
    regionId = @regionId,
  };
  var ossClient : OSS = new OSS(ossConfig);

  var fileObj = new FileForm.FileField{};
  var ossHeader = new OSS.PostObjectRequest.header{};
  var uploadRequest = new OSS.PostObjectRequest{};
  var ossRuntime = new OSSUtil.RuntimeOptions{};
  OpenApiUtil.convert(runtime, ossRuntime);
  var segmentSkyReq = new SegmentSkyRequest{};
  OpenApiUtil.convert(request, segmentSkyReq);

  if(!Util.isUnset(request.imageURLObject)) {
    authResponse = authClient.authorizeFileUploadWithOptions(authRequest, runtime);
    ossConfig.accessKeyId = authResponse.body.accessKeyId;
    ossConfig.endpoint = OpenApiUtil.getEndpoint(authResponse.body.endpoint, authResponse.body.useAccelerate, @endpointType);
    ossClient = new OSS(ossConfig);

    fileObj = new FileForm.FileField{
      filename = authResponse.body.objectKey,
      content = request.imageURLObject,
      contentType = '',
    };
    ossHeader = new OSS.PostObjectRequest.header{
      accessKeyId = authResponse.body.accessKeyId,
      policy = authResponse.body.encodedPolicy,
      signature = authResponse.body.signature,
      key = authResponse.body.objectKey,
      file = fileObj,
      successActionStatus = '201',
    };
    uploadRequest = new OSS.PostObjectRequest{
      bucketName = authResponse.body.bucket,
      header = ossHeader,
    };
    ossClient.postObject(uploadRequest, ossRuntime);
    segmentSkyReq.imageURL = `http://${authResponse.body.bucket}.${authResponse.body.endpoint}/${authResponse.body.objectKey}`;
  }
  var segmentSkyResp = segmentSkyWithOptions(segmentSkyReq, runtime);
  return segmentSkyResp;
}

